#include <iostream>
#include <vector>

int calcK(int n, int k)
{
    int fab[10] = {0};
    fab[0] = 1;
    fab[1] = 1;
    for (int i = 1; i < 10; i++)
    {
        fab[i] = i * fab[i - 1];
    }

    std::vector<int> pre(n + 1);
    for (int i = 1; i <= n; i++)
        pre[i] = i;

    k = k - 1;
    std::vector<int> nums;
    for (int i = 1; i <= n; i++)
    {
        int ww = k / fab[n - i];
        nums.push_back(pre[ww + 1]);
        pre.erase(pre.begin() + ww + 1);
        k = k % fab[n - i];
    }

    int ret = 0;
    for (int i = 0; i < nums.size(); i++)
    {
        ret = ret * 10 + nums[i];
    }

    return ret;
}

int main()
{
    int n, k;
    std::cin >> n;
    std::cin >> k;

    int ret = calcK(n, k);
    std::cout << ret << std::endl;

    return 0;
}